package router

import (
	"LibraryManagementSys/internal/repository/dao"
	midware "LibraryManagementSys/internal/router/middleware"
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// NewHttpServer 创建一个 HttpServer 对象
// @return *gin.Engine
func NewHttpServer() *gin.Engine {
	r := gin.New()

	r.Use(cors.Default(), midware.ZapLoggerMiddleware(), gin.Recovery())

	r.HandleMethodNotAllowed = true // 405

	r.MaxMultipartMemory = 8 << 20 // 8M

	if err := dao.New(); err != nil {
		zap.S().Errorf("初始化 MySQL 数据库连接失败: %s", err)
	}

	setupRouterAPI(r)

	setupStaticRouter(r)

	return r
}
